The present invention relates generally to software programming language compilers, and more particularly, to a compiler adapted to compile a program with operators for composing programming abstractions.
Central to all programming languages is the concept of “programming abstractions”. Programming abstractions as used herein describe functional behavior in computer programs through, for example, functions, procedures, or methods. Programming abstractions have the qualities of software code embedding, factorization, and reuse.
Code embedding refers to the use of programming abstractions (also referred to herein as “abstractions”) as building blocks, where abstractions are able to call each other. Code factorization refers to the avoidance of code duplication associated with abstractions in a program. Code reuse refers to the avoidance of duplicating abstractions to develop additional functionality.
More specifically, code factorization avoids the duplication of “n” similar code segments if they are needed at “n” different locations in a software program. These different segments can be transformed into a common abstraction which can be invoked “n” times at a single location in the software program. This operation is called an abstraction because some of the programming instructions are changed in order to operate on variables instead of values. These variables constitute the execution environment of the abstraction, where the value of the variables is specified at runtime.
For example, the operation “10+1” can be abstracted into an abstraction called a λ-abstraction (i.e., lambda-abstraction) that has the form “λ x:int.x+1”, where 10 is now defined as the variable “x” of type integer (i.e., “int”). In effect, the lambda-abstraction has generalized the operation “10+1” making it applicable to any integer, instead of a constant (e.g., 10). Consequently if this lambda-abstraction is called “F”, then F (10) will compute 11 and F (11) or F (F (10)) will compute 12.
It is therefore advantageous to define computer programs using abstractions to simplify software design by breaking down a complex monolithic program into smaller sub-programs. In addition, programming using abstractions has the additional benefit of simplifying quality assurance testing. For instance, testing a plurality of small sub-programs is easier than testing a large monolithic program because the context of each sub-program is more explicit and the branching complexity is simplified.
Besides code factorization, abstractions enable code reuse. That is, previously created abstractions can be reused when new software is developed by programmers. The reuse of abstractions may be as simple as copying abstractions from a repository of abstractions or from an existing program. In addition, the reuse of abstractions may involve the use of function previously created to create new function.
The creation of a new abstraction that combines the function of two or more existing abstractions is defined herein as the “composition of programming abstractions”. Current software programming techniques are poorly adapted to facilitate the composition of abstractions in a structured and a formal manner; indeed, existing techniques achieve reuse through two basic techniques that simply reuse existing approaches for composing operators that work either by duplicating code defining abstractions or by directly calling abstractions (e.g., by nesting calls). These current techniques for composing abstractions results in the production of unnecessary code at compile time.
For example, assume an existing ∇-abstraction (i.e., nabla-abstraction) “P” that takes any integer “x” and computes its double as output “y” is defined as “P=∇ x: int, y: int .(y:=2*x)”. Existing techniques for creating a new abstraction “PP” that encapsulates two subsequent calls to the abstraction “P” would be defined as “PP=∇ x: int, y: int .(y:=P(P(x))”. Execution of the composed abstraction PP(3) would produce 12. However this method for composing abstractions could be more efficient because P(P(x)) requires more instructions than necessary to carry out the operation.
Accordingly, it would be desirable to provide a programming language and compiler adapted to compose programming abstractions. Such a programming language and compiler would advantageously speed and simplify program development and maintenance by facilitating the combination of existing abstractions in a structured and formal manner.